package com.wuyan.locationdog.view

import android.content.Context
import android.graphics.Color
import android.graphics.Typeface
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.ImageView
import android.widget.TextView
import com.arcsoft.commonbase.databinding.DialogAgreePrivacyBinding
import com.arcsoft.commonbase.ext.gone
import com.arcsoft.commonbase.ext.invisible
import com.arcsoft.commonbase.ext.visible
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.contrarywind.view.WheelView
import com.wuyan.locationdog.R
import com.wuyan.locationdog.databinding.LoginActivityBinding
import com.wuyan.locationdog.databinding.PopTimeSelectBinding
import leifu.shapelibrary.ShapeView
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.TranslationConfig


class TimeSelectPopup(context: Context?, var sureCallback: ((String) -> Unit)? = null) : BasePopupWindow(context) {


    var payType = "2"
    var mBinding: PopTimeSelectBinding? = null

    init {
        contentView = createPopupById(R.layout.pop_time_select)
        popupGravity = Gravity.BOTTOM
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        mBinding = PopTimeSelectBinding.bind(contentView)

        mBinding?.apply {
            tab1.setOnClickListener {
                tabResetUi()
                tab1.setTextSize(16F)
                tab1.setTextColor(Color.parseColor("#323233"))
                tab1Line.visible()

                noTime.gone()
                hour.visible()
                min.visible()
            }
            tab2.setOnClickListener {
                tabResetUi()
                tab2.setTextSize(16F)
                tab2.setTextColor(Color.parseColor("#323233"))
                tab2Line.visible()

                noTime.gone()
                hour.visible()
                min.visible()
            }
            tab3.setOnClickListener {
                tabResetUi()
                tab3.setTextSize(16F)
                tab3.setTextColor(Color.parseColor("#323233"))
                tab3Line.visible()

                noTime.visible()
                hour.gone()
                min.gone()
            }
            btnClose.setOnClickListener {
                dismiss()
            }
            btnSure.setOnClickListener {
                dismiss()
            }

            hour.apply {
                val lists = mutableListOf<String>()
                for (i in 0 until 24) {
                    lists.add("${i}时")
                }
                setCyclic(false)
                currentItem = 12
                adapter = ArrayWheelAdapter<String>(lists)
            }
            min.apply {
                val lists = mutableListOf<String>()

                for (i in 0 until 60) {
                    lists.add("${i}分")
                }
                setCyclic(false)
                currentItem = 30

                adapter = ArrayWheelAdapter<String>(lists)
            }
            noTime.apply {
                val lists = mutableListOf<String>()
                lists.add("设备不休眠")
                setCyclic(false)
                adapter = ArrayWheelAdapter<String>(lists)
            }
        }

    }

    /**
     * 粗体 布局 下划线等切换ui
     */
    private fun PopTimeSelectBinding.tabResetUi() {

        tab1Line.invisible()
        tab2Line.invisible()
        tab3Line.invisible()

        tab1.setTextSize(14F)
        tab2.setTextSize(14F)
        tab3.setTextSize(14F)

        tab1.setTextColor(Color.parseColor("#969799"))
        tab2.setTextColor(Color.parseColor("#969799"))
        tab3.setTextColor(Color.parseColor("#969799"))

    }

    override fun onCreateShowAnimation(): Animation? {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.FROM_BOTTOM)
            .toShow()
    }

}
